package jdbc;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.rowset.serial.SerialBlob;

import org.apache.cassandra.utils.Hex;

import com.google.common.primitives.Bytes;

public class HiveDriverTest {

	/**
	 * @param args
	 * @throws SQLException 
	 * @throws NullPointerException 
	 */
	public static void main(String[] args) throws Exception {
		String host=System.getProperty("url","jdbc:laud://192.168.3.1:9170?data_port=9091&support_function=true&hive=true");
		Class.forName("cn.edu.thu.laud.jdbc.LaUDDriver");
		Connection con = DriverManager.getConnection(host, "", "");
		Statement statement=con.createStatement();
//		try{
//			statement.execute("drop database dbtest2 with olap");
//		}catch (Exception e) {
//			System.err.println(e.getMessage());
//		}
		
//		try{
//			statement.execute("create database dbtest2 with olap");
//		}catch (Exception e) {
//			System.err.println(e.getMessage());
//		}
		statement.execute("use dbtest1 with olap");
//		try{
//			statement.execute("create table table1(id int,cont string) row format delimited fields terminated by '\001' stored as textfile with olap");
//		}catch (Exception e) {
//			System.err.println(e.getMessage());
//		}
//		try{
//			statement.execute("create table studentinsert(name string) location '/yiguoleihive/2/' with olap");
//		}catch (Exception e) {
//			System.err.println(e.getMessage());
//		}
//		//statement.execute("create table tbtest2(id int,age int) with olap");
		//statement.execute("show tables with olap");
		statement.execute("set hive.map.aggr=true");
		statement.execute("select count(*) from tbtest1 with olap");
		//statement.execute("describe  tbtest1 with olap");
		ResultSet rs=statement.getResultSet();
		while(rs.next()){
			System.out.println(rs.getObject(1));
		}
		statement.close();

		System.err.println("-------------------close-------------------------");
		con.close();
	}

}
